$(function() {
	// 注window.xxx是全局变量，外面可以访问，其他是内部变量，外面访问不了
	var selectedArr = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ];// 注：在页面定义场次数目，这里在根据场次数目生成数组，可灵活适用于足彩其他几个玩法
	var selected_class = 'dcchose';
	var unselected_class = '';
	window.selectAt = function(matchIndex, item, event) {
		var createForm = getCreateForm();
		var el = createForm.elements['createForm.items[' + matchIndex + '].' + item];
		var liEl = document.getElementById('li_' + matchIndex + '_' + item);
		if (event != null) {
			Event_stopPropagation(event);
			var target = Event_target(event);
			if (target.id != el.id)
				el.checked = !el.checked;
		} else {
			el.checked = !el.checked;
		}
		if (!el.checked) {
			selectedArr[matchIndex] -= 1;
			liEl.className = unselected_class;
		} else {
			selectedArr[matchIndex] += 1;
			liEl.className = selected_class;
		}
		countUnits();
	};
	
	window.columnSelect = function(obj, item) {
		var createForm = getCreateForm();
		var checked = obj.checked;
		var className = checked ? selected_class : unselected_class;
		for ( var i = 0; i < selectedArr.length; i++) {
			var el = createForm.elements['createForm.items[' + i + '].' + item];
			if (el.checked != checked) {
				if (checked) {
					selectedArr[i] += 1;
				} else {
					selectedArr[i] -= 1;
				}
				el.checked = checked;
				document.getElementById('li_' + i + '_' + item).className = className;
			}
		}
		countUnits();
	};

	function countUnits() {
		var units = 1;
		for ( var i = 0, len = selectedArr.length; i < len; i++) {
			units *= selectedArr[i];
			if (units == 0)
				break;
		}
		updateBetUnits(units);
	}	
});